package com.jumeng.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.wxpay.sdk.WXPayUtil;
import com.jumeng.entity.OrderEntity;
import com.jumeng.server.CourseUserRelationService;
import com.jumeng.server.OrderService;
import com.jumeng.server.PayOrderService;
import com.jumeng.util.StreamUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@RestController("/api/pay")
@Api(tags = "支付接口")
@Slf4j
public class PayOrderController {

    @Autowired
    private PayOrderService payOrderService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private CourseUserRelationService courseUserRelationService;

    @PostMapping(value = "pay")
    @ApiOperation("获取微信支付二维码接口")
    public Map<String, String> wechatPayOrder(@RequestParam("orderId") String orderId, @RequestParam("money") String money, @RequestParam("body") String body, @RequestParam("openId") String openId) {
        return payOrderService.h5WeChatPay(orderId, money, body, openId);
    }

    /**
     * 微信支付完成后，微信回调的页面
     *
     * @return
     */
    @GetMapping("/backll")
    public String backll() {
        System.out.println("-------------微信回调---------------:");
        return "pay/back"; //Result.success("no");
    }

    /**
     * 查询订单，用于微信回调接口时查询订单是否完成。用户主动触发
     *
     * @param orderId
     * @return
     */
    @GetMapping("/checkList")
    public String CheckList(@RequestParam("orderId") String orderId) {
//        weChatPayService.CheckList(orderId);
        return "pay/back";
    }


}
